import store from '@/store'

// 获取字典里的类型
export const getDictGoodsTypeName = (key: string) => {
  return store.getters['goodsType/getName'](key)
}

export const getGoodsTypeName = (key: string) => {
  return store.getters['goodsType/getGoodsTypeName'](key)
}
// 获取航站楼名称
export const getTerminalName = (key: string) => {
  return store.getters['terminal/getName'](key)
}

export const getDepositPlaceName = (key: string) => {
  return store.getters['depositPlace/getName'](key)
}

// 有据机构ID获取机构名称
export const getOrganName = (organId: string) => {
  const tree = store.getters['user/getOrganTree']
  return getOrganNameByOrganId(tree, organId)
}
const getOrganNameByOrganId = (tree: any, organId: string) => {
  let name = ''
  tree.forEach((ele: any) => {
    if (ele.data.organId === organId) {
      name = ele.data.name
    }
    if (name === '' && ele.children?.length > 0) {
      name = getOrganNameByOrganId(ele.children, organId)
    }
  })
  return name
}

export const deepFn = (tree: any[], fn = (record: any): void => { }, key = 'children') => {
  tree.forEach(item => {
    fn(item);
    if (item?.[key]?.length) deepFn(item?.[key], fn, key)
  })
}